<template>
	<div class="zhengtuojianhuo">
		<van-nav-bar :fixed="true" class="navBar" title="库存日志" left-arrow @click-left="$router.go(-1)"></van-nav-bar>




		<div class="goodsFromWarp">
				<div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName"  style="width: 120px;" >商品编码：</div>
						</div>
						<van-field
							 class="skuInput"
							 v-model="editForm.itemid"
							 placeholder="请填写仓位编码"
							 clearable
						 />
				</div>


				<div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName"  style="width: 120px;" >开始时间：</div>
						</div>
						<van-field
							 class="skuInput"
							 v-model="editForm.bdatef"
							 placeholder="请填写开始时间"
							 clearable
						 />
						 <div class="searchBtn">
						 	<button :disabled="isdisabled" @click="selectTime('start')">
						 		<van-icon name="ellipsis" color="#1989fa"  />
						 	</button>
						 </div>
				</div>

				<div class="goodsInputWarp">
						<div class="goodsInputLabel">
							<div class="goodsInputBorder"></div>
							<div class="skuName"  style="width: 120px;" >结束时间：</div>
						</div>
						<van-field
							 class="skuInput"
							 v-model="editForm.bdatet"
							 placeholder="请填写结束时间"
							 clearable
						 />
						 <div class="searchBtn" @click="selectTime('end')" >
						 	<button :disabled="isdisabled">
						 		<van-icon name="ellipsis" color="#1989fa"  />
						 	</button>
						 </div>
				</div>




		</div>

		<van-popup v-model="isMonthshow" position="bottom" :style="{ height: '300px' }" >
		    <van-datetime-picker
		        v-model="currentMonthDate"
		        type="date"
		        title="选择年月日"
		        :min-date="minMonthDate"
		        :max-date="maxMonthDate"
		        :formatter="formatterMonth"
		        @confirm="selectMonthConfirm"
		    />
		</van-popup>


		<div class="skuBtn" style="justify-content: flex-end;">
			<van-button type="info" :disabled="isdisabled" @click="lingquBtn()">查询任务</van-button>
		</div>

		<div class="carCardWarp">
			<div class="carCard" v-for="(item,index) in lingquData" :key="index">

				<van-row class="goodRow" style="margin-top: 10px;">
				  <van-col span="24"> <span>单号:</span>{{item.ywbill}}</van-col>
				</van-row>


				<van-row class="goodsNameWarp">
						<span class="label">商品：</span>
						<span class="value"> {{item.spname}}-{{item.itemid}}</span>
				</van-row>



				<van-row class="goodRow">
				  <van-col span="24"> <span>原仓位:</span>{{item.cwnof}}</van-col>
				</van-row>

				<van-row class="goodRow">
				  <van-col span="24"> <span>至仓位:</span>{{item.cwnot}}</van-col>
				</van-row>

				<van-row class="goodRow" style="margin-top: 10px;">
				  <van-col span="24"> <span>时间:</span>{{item.btime}}</van-col>
				</van-row>


				<van-row class="goodRow" style="margin-top: 10px;">
				  <van-col span="12"> <span>箱装:</span>{{item.unit}}</van-col>
				  <van-col span="12"> <span>箱数:</span>{{item.pack}}</van-col>
				</van-row>

				<van-row class="goodRow" style="margin-top: 10px;">
				  <van-col span="12"> <span>散数:</span>{{item.qty}}</van-col>
				</van-row>




				<van-row class="goodRow" style="margin-top: 10px;">
				  <van-col span="24"> <span>业务:</span>{{item.optype}}</van-col>
				</van-row>



				<van-row class="goodRow" style="margin-top: 10px;">
				  <van-col span="24"> <span>明细账:</span>{{item.seq_no}}</van-col>
				</van-row>
			</div>
		</div>
	</div>
</template>

<script>

export default {
  name: 'kucunrizhi',
  data() {
    return {
			editForm:{
				itemid:'',  //C0212852
				bdatef:'',
				bdatet:'',
			},
			checked:false,
			isdisabled:false,
			lingquData:[],
			isLingQuVisible:false,

			currentMonthDate:'',
			minMonthDate:new Date(2020, 0, 1),
			maxMonthDate:new Date(2099, 10, 1),
			currentMonthDate: new Date(),
			isMonthshow:false,
			isTime:''
		};
  },
	computed: {
		 ryuser: function(){
			 return this.GWO(true).gUSER;
		 },
	},
  methods: {
		selectTime(value){
			console.log(value)
			this.isTime = value
			this.isMonthshow =!this.isMonthshow
		},
		formatterMonth(type, val) {
		    if (type === 'year') {
		        return `${val}年`;
		    } else if (type === 'month') {
		        return `${val}月`;
		    }else if (type === 'day') {
		        return `${val}日`;
		    }
		    return val;
		},
		selectMonthConfirm(value){
			if(this.isTime == 'start'){
				this.editForm.bdatef =  this.format_yyyyMMdd(value)
			}else if(this.isTime == 'end'){
				this.editForm.bdatet =  this.format_yyyyMMdd(value)
			}
			this.isMonthshow =!this.isMonthshow
		},
		lingquBtn(){
			if(this.checked){
				this.editForm.yn_lscw = 'Y'
			}else{
				this.editForm.yn_lscw = 'N'
			}
			var _self = this;
			_self.$store.commit('showLoading');
			var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			this.MYPOST({
					'method':'dgate',
					'pname':'f_wmsa_y_chaxun',
					'i':this.FNULLE([
					'opmode','Y_KCRZ_qrybill',
						'czyid',this.ryuser.operatorid,
						'kqid', this.ryuser.kqid,
						'itemid',this.editForm.itemid,
						'bdatef',this.editForm.bdatef,
						'bdatet',this.editForm.bdatet,
					])
				},'库存日志',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了
					_self.$toast.fail('查询失败')
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					console.log("得到库存日志")
					console.log(rtn_json_obj)
					_self.lingquData = rtn_json_obj
					if(_self.lingquData.length > 0){

					}else{
						_self.$toast.fail('暂无数据')
					}
				}
			});
		},
  },
  mounted() {
		this.editForm.bdatef =  this.format_yyyyMMdd(new Date)
		this.editForm.bdatet =  this.format_yyyyMMdd(new Date)
  },
	components: {

	},
};
</script>

<style lang="scss" scoped>
	// 引入公共样式
	@import '@/assets/css/base.scss';
	@import '@/assets/css/input.scss';
	div.zhengtuojianhuo{
		padding-top: 50px;
	}



	div.carCardWarp{
		width: 94%;
		margin-left: 3%;
		margin-right: 3%;
		margin-top: 20px;
		font-size: 20px;
		font-weight: bold;
		div.carCard{
			position: relative;
			border-left: 5px solid #4998FF;
			box-sizing: border-box;
			padding-left: 10px;
			padding-right: 10px;
			border-radius:5px;
			background-color: #fff;
			padding-top: 10px;
			padding-bottom: 10px;
			margin-bottom:15px;
			div.status{
				position: absolute;
				right: 0;
				top: 0;
				width: 65px;
				height: 30px;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
				font-size: 12px;
				border-radius: 0px 10px 0px 10px;
			}
			div.goodRow{
				margin-bottom:8px;
				span{
					display: inline-block;
					width:80px;
				}
			}
			div.goodsTitleRow{
				display: flex;
				width: 100%;
				div.goodsTitleLabel{
					width: 80px;
				}
				div.skuNoTitle{
					width: calc(100% - 80px);
				}
			}
		}
	}


	.goodsNameWarp{
		font-size: 20px;
		display: flex;
		margin-bottom:5px;
		font-weight: bold;
		display: flex;
		flex: 1;
		span{
			display: block;
		}
		.label{
			width:80px;
		}
		.value{
			line-height: 22px;
			width: calc(100% - 80px);
		}
	}


</style>
